-
Notifications
You must be signed in to change notification settings - Fork 6k
Add log buffering docs #46232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add log buffering docs #46232
Conversation
1ad5e4b
to
b8fb0b7
Compare
b8fb0b7
to
5cbf2fc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple typo and grammatical suggestions.
Co-authored-by: Rageking8 <[email protected]>
Co-authored-by: Rageking8 <[email protected]>
Co-authored-by: Rageking8 <[email protected]>
@IEvangelist @gewarren may I get it reviewed, please? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this. I left some suggestions.
- name: Log Sampling | ||
href: ../../core/extensions/log-sampling.md | ||
- name: Log Buffering |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- name: Log Sampling | |
href: ../../core/extensions/log-sampling.md | |
- name: Log Buffering | |
- name: Log sampling | |
href: ../../core/extensions/log-sampling.md | |
- name: Log buffering |
- name: Log Sampling | ||
href: ../core/extensions/log-sampling.md | ||
- name: Log Buffering |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- name: Log Sampling | |
href: ../core/extensions/log-sampling.md | |
- name: Log Buffering | |
- name: Log sampling | |
href: ../core/extensions/log-sampling.md | |
- name: Log buffering |
|
||
Buffered logs are stored in temporary circular buffers in process memory, and the following conditions apply: | ||
|
||
- If the buffer is full, the oldest logs will be dropped and never emitted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If the buffer is full, the oldest logs will be dropped and never emitted. | |
- If the buffer is full, the oldest logs are dropped and never emitted. |
Buffered logs are stored in temporary circular buffers in process memory, and the following conditions apply: | ||
|
||
- If the buffer is full, the oldest logs will be dropped and never emitted. | ||
- If you want to emit the buffered logs, you can call `Flush()` on the `GlobalLogBuffer` or `PerRequestLogBuffer` class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If you want to emit the buffered logs, you can call `Flush()` on the `GlobalLogBuffer` or `PerRequestLogBuffer` class. | |
- If you want to emit the buffered logs, you can call <xref:Microsoft.Extensions.Diagnostics.Buffering.LogBuffer.Flush> on the <xref:Microsoft.Extensions.Diagnostics.Buffering.GlobalLogBuffer> or <xref:Microsoft.Extensions.Diagnostics.Buffering.PerRequestLogBuffer> class. |
There are two buffering strategies available: | ||
|
||
- Global buffering: Buffers logs across the entire application. | ||
- Per-request buffering: Buffers logs for each individual HTTP request if available, otherwise - buffers to the global buffer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Per-request buffering: Buffers logs for each individual HTTP request if available, otherwise - buffers to the global buffer. | |
- Per-request buffering: Buffers logs for each individual HTTP request if available; otherwise, buffers to the global buffer. |
|
||
Log buffering offers a trade-off between memory usage and log storage costs. Buffering logs in memory allows you to: | ||
|
||
1. Selectively emit logs based on runtime conditions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Selectively emit logs based on runtime conditions. | |
1. Selectively emit logs based on run-time conditions. |
- Set appropriate buffer size limits based on your application's memory constraints. | ||
- Use per-request buffering for web applications to isolate logs by request. | ||
- Configure auto-flush duration carefully to balance memory usage and log availability. | ||
- Implement explicit flush triggers for important events (errors, warnings, etc.). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Implement explicit flush triggers for important events (errors, warnings, etc.). | |
- Implement explicit flush triggers for important events (such as errors and warnings). |
|
||
- Log buffering is not supported in .NET 8 and earlier versions. | ||
- The order of logs is not guaranteed to be preserved. However, original timestamps are preserved. | ||
- Custom configuration per each logging provider is not supported. Same configuration is used for all providers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Custom configuration per each logging provider is not supported. Same configuration is used for all providers. | |
- Custom configuration per each logging provider is not supported. The same configuration is used for all providers. |
- The order of logs is not guaranteed to be preserved. However, original timestamps are preserved. | ||
- Custom configuration per each logging provider is not supported. Same configuration is used for all providers. | ||
- Log scopes are not supported. This means that if you use the <xref:Microsoft.Extensions.Logging.ILogger.BeginScope%2A> method, the buffered log records will not be associated with the scope. | ||
- Not all information of the original log record is preserved. Log buffering internally uses <xref:Microsoft.Extensions.Logging.Abstractions.BufferedLogRecord> class when flushing, and its following properties are always empty: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Not all information of the original log record is preserved. Log buffering internally uses <xref:Microsoft.Extensions.Logging.Abstractions.BufferedLogRecord> class when flushing, and its following properties are always empty: | |
- Not all information of the original log record is preserved. Log buffering internally uses <xref:Microsoft.Extensions.Logging.Abstractions.BufferedLogRecord> class when flushing, and the following of its properties are always empty: |
|
||
## See also | ||
|
||
- [Log Sampling](log-sampling.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [Log Sampling](log-sampling.md) | |
- [Log sampling](log-sampling.md) |
Summary
Fixes #46231
Internal previews